//
//  PlaneOrderHeaderView.m
//  旅游趣吧
//
//  Created by 高亦 on 15/11/5.
//  Copyright © 2015年 lampshade. All rights reserved.
//  飞机票订单头部视图

#import "PlaneOrderHeaderView.h"
#import "SqliteHelper.h"

@interface PlaneOrderHeaderView()

@property (nonatomic, weak) UILabel *carrierName;
@property (nonatomic, weak) UILabel *planeTypeName;
@property (nonatomic, weak) UILabel *offTime;
@property (nonatomic, weak) UILabel *arrTime;
@property (nonatomic, weak) UILabel *offAirPort;
@property (nonatomic, weak) UILabel *arrAirPort;

@end

@implementation PlaneOrderHeaderView
- (UIView *)setPlaneOrderHeaderView:(UITableView *)tableView setListModel:(FlightListModel *)listModel setCodeModel:(FlightCodeListModel *)codeModel{
    
    self.listModel = listModel;
    self.codeListModel = codeModel;
    
    CGFloat headerViewH = tableView.frame.size.height;
    CGFloat headerViewW = tableView.frame.size.width;
    
    UIView *headerView = [[UIView alloc]init];
    headerView.frame = CGRectMake(0, 0, headerViewW, headerViewH/5);
    CGFloat headerAppH = headerView.frame.size.height/3;
    
    //航空公司名称
    UILabel *carrierName = [[UILabel alloc]init];
    carrierName.frame = CGRectMake(8, 0, headerViewW/2,headerAppH);
    carrierName.font = [UIFont systemFontOfSize:15.0];
    self.carrierName = carrierName;
    [headerView addSubview:carrierName];

    //飞机类型名称
    UILabel *planeTypeName = [[UILabel alloc]init];
    planeTypeName.frame = CGRectMake(headerViewW/2, 0, headerViewW/2-8, headerAppH);
    planeTypeName.font = [UIFont systemFontOfSize:15.0];
    planeTypeName.textAlignment = NSTextAlignmentRight;
    self.planeTypeName = planeTypeName;
    [headerView addSubview:planeTypeName];
    
    //出发时间
    UILabel *offTime = [[UILabel alloc]init];
    offTime.frame = CGRectMake(8, headerAppH, headerViewW/2, headerAppH);
    offTime.font = [UIFont systemFontOfSize:15.0];
    self.offTime = offTime;
    [headerView addSubview:offTime];
    
    //到达时间
    UILabel *arrTime = [[UILabel alloc]init];
    arrTime.frame = CGRectMake(headerViewW/2, headerAppH, headerViewW/2-8, headerAppH);
    arrTime.font = [UIFont systemFontOfSize:15.0];
    arrTime.textAlignment = NSTextAlignmentRight;
    self.arrTime = arrTime;
    [headerView addSubview:arrTime];
    
    //出发机场名称
    UILabel *offAirPort = [[UILabel alloc]init];
    offAirPort.frame = CGRectMake(8, headerAppH*2, headerViewW/2, headerAppH);
    offAirPort.font = [UIFont systemFontOfSize:15.0];
    self.offAirPort = offAirPort;
    [headerView addSubview:offAirPort];
    
    //到达机场名称
    UILabel *arrAirPort = [[UILabel alloc]init];
    arrAirPort.frame = CGRectMake(headerViewW/2, headerAppH*2, headerViewW/2-8, headerAppH);
    arrAirPort.font = [UIFont systemFontOfSize:15.0];
    arrAirPort.textAlignment = NSTextAlignmentRight;
    self.arrAirPort = arrAirPort;
    [headerView addSubview:arrAirPort];
    
    [self setDataForHeaderView];
    
    return headerView;
}

//设置标签数据
- (void)setDataForHeaderView{
    
    self.carrierName.text = self.listModel.CarrierName;
    self.planeTypeName.text = self.listModel.PlanTypeName;
    
    NSMutableString *dptTime = [[NSMutableString alloc]initWithString:self.listModel.DptTime];
    [dptTime insertString:@":" atIndex:2];
    NSMutableString *arrTime = [[NSMutableString alloc]initWithString:self.listModel.ArrTime];
    [arrTime insertString:@":" atIndex:2];
    self.offTime.text = dptTime;
    self.arrTime.text = arrTime;
    
    NSString *off_AirPort = [[SqliteHelper alloc]queryCityName:self.listModel.DptAirport];
    NSString *arr_AirPort = [[SqliteHelper alloc]queryCityName:self.listModel.ArrAirport];
    self.offAirPort.text = off_AirPort;
    self.arrAirPort.text = arr_AirPort;
}

@end
